//
//  HZPeiziAccountView.m
//  Stock_Stategy
//
//  Created by MayerF on 2017/11/27.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZPeiziAccountView.h"
#import "HZUpdownLable.h"

@interface HZPeiziAccountView()
@property (nonatomic, strong)HZUpdownLable *pZCZZ;
@property (nonatomic, strong)HZUpdownLable *pCCSZ;
@property (nonatomic, strong)HZUpdownLable *pZJYE;
@property (nonatomic, strong)HZUpdownLable *pKYZJ;
@property (nonatomic, strong)HZUpdownLable *pDJZJ;
@property (nonatomic, strong)UIButton *pMore;

@property (nonatomic, strong)UIView *pLine1;
@property (nonatomic, strong)UIView *pLine2;
@property (nonatomic, strong)UIView *pLine3;
@property (nonatomic, strong)UIView *pLine4;
@property (nonatomic, strong)UIView *pLine5;
@property (nonatomic, strong)UIView *pLine6;
@property (nonatomic, strong)UIView *pLine7;
@end

@implementation HZPeiziAccountView

#pragma mark -
#pragma mark 生命周期
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initCommon];
        [self initConstraints];
    }
    return self;
}
- (void)initCommon {
    _pZCZZ = [HZUpdownLable new];
    _pCCSZ = [HZUpdownLable new];
    _pZJYE = [HZUpdownLable new];
    _pKYZJ = [HZUpdownLable new];
    _pDJZJ = [HZUpdownLable new];
    _pMore = [UIButton new];
    
    _pLine1 = [UIView new];
    _pLine2 = [UIView new];
    _pLine3 = [UIView new];
    _pLine4 = [UIView new];
    _pLine5 = [UIView new];
    _pLine6 = [UIView new];
    _pLine7 = [UIView new];
    
    _pLine1.backgroundColor = _pLine2.backgroundColor = _pLine3.backgroundColor = kMYHexToRGB(0xf6f6f6, 1);
    _pLine4.backgroundColor = _pLine5.backgroundColor = _pLine6.backgroundColor = _pLine7.backgroundColor = kMYHexToRGB(0xf6f6f6, 1);
    
    [_pZCZZ setUptext:@"--" downtext:@"资产总值"];
    [_pCCSZ setUptext:@"--" downtext:@"持仓市值"];
    [_pZJYE setUptext:@"--" downtext:@"资金余额"];
    [_pKYZJ setUptext:@"--" downtext:@"可用资金"];
    [_pDJZJ setUptext:@"--" downtext:@"冻结资金"];
//    [_pMore setTitle:@"更多" forState:UIControlStateNormal];
    [_pMore setImage:[UIImage imageNamed:@"mark_more"] forState:UIControlStateNormal];
    [_pMore setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_pMore addTarget:self action:@selector(moreOnClick) forControlEvents:UIControlEventTouchUpInside];
}
- (void)initConstraints {
    [self addSubview:_pZCZZ];
    [self addSubview:_pCCSZ];
    [self addSubview:_pZJYE];
    [self addSubview:_pKYZJ];
    [self addSubview:_pDJZJ];
    [self addSubview:_pMore];
    [self addSubview:_pLine1];
    [self addSubview:_pLine2];
    [self addSubview:_pLine3];
    [self addSubview:_pLine4];
    [self addSubview:_pLine5];
    [self addSubview:_pLine6];
    [self addSubview:_pLine7];
    
    [_pZCZZ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(10);
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(_pCCSZ.mas_left);
        make.bottom.mas_equalTo(_pKYZJ.mas_top).offset(-15);
    }];
    [_pCCSZ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pZCZZ);
        make.right.mas_equalTo(_pZJYE.mas_left);
        make.bottom.mas_equalTo(_pDJZJ.mas_top).offset(-15);
    }];
    [_pZJYE mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pZCZZ);
        make.right.mas_equalTo(self);
        make.bottom.mas_equalTo(_pMore.mas_top).offset(-15);
    }];
    [_pKYZJ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_pZCZZ);
        make.right.mas_equalTo(_pDJZJ.mas_left);
        make.bottom.mas_equalTo(self).offset(-10);
    }];
    [_pDJZJ mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_pMore.mas_left);
        make.bottom.mas_equalTo(_pKYZJ);
    }];
    [_pMore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_pZJYE);
        make.bottom.mas_equalTo(_pKYZJ);
        make.height.mas_equalTo(@[_pZCZZ, _pCCSZ, _pZJYE, _pKYZJ, _pDJZJ]);
        make.width.mas_equalTo(@[_pZCZZ, _pCCSZ, _pZJYE, _pKYZJ, _pDJZJ]);
    }];
    
    [_pLine1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_pZCZZ);
        make.centerY.mas_equalTo(self);
        make.height.mas_equalTo(0.5);
        make.width.mas_equalTo(50);
    }];
    [_pLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_pCCSZ);
        make.centerY.mas_equalTo(self);
        make.height.mas_equalTo(0.5);
        make.width.mas_equalTo(50);
    }];
    [_pLine3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_pZJYE);
        make.centerY.mas_equalTo(self);
        make.height.mas_equalTo(0.5);
        make.width.mas_equalTo(50);
    }];
    [_pLine4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_pZCZZ.mas_right);
        make.centerY.mas_equalTo(_pZCZZ);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(0.5);
    }];
    [_pLine5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_pCCSZ.mas_right);
        make.centerY.mas_equalTo(_pCCSZ);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(0.5);
    }];
    [_pLine6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_pKYZJ.mas_right);
        make.centerY.mas_equalTo(_pKYZJ);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(0.5);
    }];
    [_pLine7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_pDJZJ.mas_right);
        make.centerY.mas_equalTo(_pDJZJ);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(0.5);
    }];
}

- (void)moreOnClick
{
   LogicRouterBlock block = [self.logicManager matchLogicBlock:kLogicRouterPeiziAccountMoney];
    if (block) {
        block(nil, nil);
    }
}

- (void)updateAccountData:(HZPeiziAccountMoneyModel *)model
{
    NSString *temp = [NSString stringWithFormat:@"%0.2f", [model.total_assert floatValue]];
    [_pZCZZ setUptext:temp];
    temp = [NSString stringWithFormat:@"%0.2f", [model.mak_val floatValue]];
    [_pCCSZ setUptext:temp];
    temp = [NSString stringWithFormat:@"%0.2f", [model.balance floatValue]];
    [_pZJYE setUptext:temp];
    temp = [NSString stringWithFormat:@"%0.2f", [model.valid_balance floatValue]];
    [_pKYZJ setUptext:temp];
    temp = [NSString stringWithFormat:@"%0.2f", [model.frozen_balance floatValue]];
    [_pDJZJ setUptext:temp];
}

@end
